<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
    <div>
		<ul class="commentlist" id="discuss">
		</ul>
	</div>        
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
</fieldset>
 
<textarea class="layui-textarea" id="LAY_demo1" style="display: none"></textarea>
 
<div class="site-demo-button" style="margin-top: 20px;">
  <button class="layui-btn site-demo-layedit" data-type="content">获取编辑器内容</button>
  <button class="layui-btn site-demo-layedit" data-type="text">获取编辑器纯文本内容</button>
  <button class="layui-btn site-demo-layedit" data-type="selection">获取编辑器选中内容</button>
</div>
 
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>自定义工具栏</legend>
</fieldset>
 
<div style="margin-bottom: 20px; width: 500px;">
  <textarea class="layui-textarea" id="LAY_demo2" style="display: none"></textarea>
</div>               
          
<script src="js/layui.js" charset="utf-8"></script>
<script src="js/jquery-3.2.1.js"></script>
<script>
	$(function() {
		$.ajax({
			async : true,
			url : "../DiscussServlet",
			type : "post",
			dataType : "json",
			data : {
				op : "searchDiscuss"
			},
			success : function(result) {
				show(result)
			},
			error : function() {
				alert("异步请求失败！");
			}

		});
	});
		function show(result){
			for ( var i in result) {
				console.log(result[i]);
				if(result[i].discuss.discussId==0){
					$("#discuss").append("<li  style=\"list-style:none; background:orange;border:1px solid gray;\">"+result[i].user.userName+
							"评论："+result[i].discussContent+
							"</li>");
					findDicuss(result[i],result);
				}
			}
		}
		function findDicuss(result1,result) {
			for ( var j in result) {
			 if (result[j].discuss.discussId==result1.discussId) {
				 $("#discuss").append("<ul><li >"+result[j].user.userName+
							"评论"+result[j].discuss.user.userName+"："+result[j].discussContent+
							"</li></ul>");
				 if (result1.discussId!=0) {
					 findDicuss(result[j],result);
				}
			}
		}
	}
		 
				
	   
</script>
<script>
layui.use('layedit', function(){
  var layedit = layui.layedit
  ,$ = layui.jquery;
  
  //构建一个默认的编辑器
  var index = layedit.build('LAY_demo1');
  
  //编辑器外部操作
  var active = {
    content: function(){
      alert(layedit.getContent(index)); //获取编辑器内容
    }
    ,text: function(){
      alert(layedit.getText(index)); //获取编辑器纯文本内容
    }
    ,selection: function(){
      alert(layedit.getSelection(index));
    }
  };
  
  $('.site-demo-layedit').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  //自定义工具栏
  layedit.build('LAY_demo2', {
    tool: ['face', 'link', 'unlink', '|', 'left', 'center', 'right']
    ,height: 100
  })
});
</script>

</body>
</html>







</html>